#define _CRT_SECURE_NO_WARNINGS 1
#include<stdio.h>
#include<stdlib.h>  
#include<time.h>

void swap(int* p1, int* p2) 
{
	int tmp = *p1;
	*p1 = *p2;
	*p2 = tmp;
}

int AdjustDown(int* a, int n, int parent)
{
	int child = parent * 2 + 1;
	while (child < n)
	{
		if (&a[child] > &a[child + 1])
		{
			child++;
		}
		if (&a[child] < &a[parent])
		{
			swap(&a[child], &a[parent]);
			parent = child;
			child = child * 2 + 1;
		}
	}
}

void DataCreat()
{
	const char* file = "data.txt";
	fopen(file, "w");
	if (file == NULL)
	{
		perror("fopen failed");
		exit(-1); 
	}
	int n = 100;
	srand((unsigned int)time(NULL));
	int i = 0;
	for (i = 0; i < n; i++)
	{
		fprintf(file, "%d", rand() % 100);
	}
	fclose(file);
}

void HeapTopK(int k)
{
	const char* file = "data.txt";
	fopen(file, "r");
	
	int* a = (int*)malloc(sizeof(int) * k);
	int i = 0;
	for (i = 0; i < k; i++)
	{
		fsanf(file, "%d", a[i]);
	}
	for (i = (k - 2) / 2; i >= 0; i--)
	{
		AdjustDown(&a, k, i);
	}
	int x = 0;
	while (fscanf(file, "%d", &x) != EOF)
	{
		if (x > a[0]);
		a[0] = x;
		AdjustDown(&a, k, 0);
	}
	free(a); 
	a = NULL;
	fclose(file); 
}
int main()
{
	DataCreat();
	int k = 0;
	scanf("%d", k);
	HeapTopK(k);
	return 0;
}